/**
 * 
 */
package com.lanswon.qzsmk.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.lanswon.qzsmk.vo.ServiceObject;

/**
 * @author sun
 *
 */
public class DwzPage<T>  extends ServiceObject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8875576360114757274L;
	private int currentPage = 1; // 当前页数，默认第一页
    private int numPerPage = 20; // 每页个数，默认20
    private int totalCount = 0; // 总数，默认0
    private int pageNumShown = 10; // 页标数字多少个，默认10
    private String orderField; // 排序方式
    private String orderDirection; // 升序降序
    private List<T> list = new ArrayList<>(); // 返回的集合
    
    private int pageCount;//总页数
/*    private boolean firstPage;//首页
	private boolean lastPage;//尾页
*/	
  //计算总页数
  	public int getPageCount() {
  		pageCount=totalCount/numPerPage;
  		if(totalCount%numPerPage!=0){
  			pageCount++;
  		}	
  		return pageCount;
  	}
  	public void setPageCount(int pageCount) {
  		this.pageCount = pageCount;
  	}
	//判断是否是首页
	public boolean isFirstPage() {
		return currentPage<=1?true:false;
	}
/*	public void setFirstPage(boolean firstPage) {
		this.firstPage = firstPage;
	}*/
	//判断是否是尾页
	public boolean isLastPage() {
		return currentPage>=getPageCount()?true:false;
	}
/*	public void setLastPage(boolean lastPage) {
		this.lastPage = lastPage;
	}*/
	/**
	 * @param currentPage
	 * @param numPerPage
	 * @param totalCount
	 */
	public DwzPage(int currentPage, int numPerPage, int totalCount) {
		super();
		this.currentPage = currentPage;
		this.numPerPage = numPerPage;
		this.totalCount = totalCount;
	}




	/**
     * 得到分页后的数据(list分页)
     *
     * @param pageNum 页码
     * @return 分页后结果
     */
    public List<T> getPagedList() {
        int fromIndex = (currentPage - 1) * numPerPage;
        if (fromIndex >= list.size()) {
            return Collections.emptyList();//空数组
        }
        if(fromIndex<0){
            return Collections.emptyList();//空数组
        }
        int toIndex = currentPage * numPerPage;
        if (toIndex >= list.size()) {
            toIndex = list.size();
        }
        return list.subList(fromIndex, toIndex);
    }
    
    
    
    
    public int getNumPerPage() {
        return numPerPage;
    }
 
    public void setNumPerPage(int numPerPage) {
        this.numPerPage = numPerPage;
    }
 
    public int getTotalCount() {
        return totalCount;
    }
 
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
 
    public String getOrderField() {
        return orderField;
    }
 
    public void setOrderField(String orderField) {
        this.orderField = orderField;
    }
 
    public String getOrderDirection() {
        return orderDirection;
    }
 
    public void setOrderDirection(String orderDirection) {
        this.orderDirection = orderDirection;
    }
 
    public List<T> getList() {
        return list;
    }
 
    public void setList(List<T> list) {
        this.list = list;
    }
 
    public int getPageNumShown() {
        return pageNumShown;
    }
 
    public void setPageNumShown(int pageNumShown) {
        this.pageNumShown = pageNumShown;
    }
 
    public int getCurrentPage() {
        return currentPage;
    }
 
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
 
    
}

